package com.wsoft.system.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author: zhanggukai
 * @date: 2022年07月23日 16:02
 */

public interface CommonMapper {
    /**
     * 判断表是否存在某字段
     * @param tableName
     * @param filedName
     * @return
     */
    @Select(value = "select count(1) from information_schema.columns where table_name = #{tableName} and column_name = #{filedName}")
    int getFieldExists(@Param("tableName") String tableName, @Param("filedName") String filedName);

    /**
     * 获取所有表
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    @Select("select * from information_schema.TABLES where TABLE_SCHEMA = (select database())")
    List<Map> listTable();

    /**
     * 获取所有表字段
     * @param tableName
     * @return
     */
    @InterceptorIgnore(tenantLine = "true")
    @Select("select * from information_schema.COLUMNS where TABLE_SCHEMA = (select database()) and TABLE_NAME = #{tableName}")
    List<Map> listTableColumn(String tableName);
}
